package projectodedalo.servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import projectodedalo.excepcion.DAOExcepcion;
import projectodedalo.modelo.Usuario;
import projectodedalo.negocio.GestionReunion;

/**
 * Servlet implementation class GrabaReunionesServlet
 */
@WebServlet("/GrabaReunionesServlet")
public class GrabaReunionesServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GrabaReunionesServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		System.out.println("GrabaReunionesServlet");
		String xasesoria = request.getParameter("asesoria");
		String xcalifica = request.getParameter("califica");

		HttpSession session = request.getSession();
		Usuario usuario_actual = (Usuario)session.getAttribute("USUARIO_ACTUAL");
		int xcodigoIdea = (int) session.getAttribute("CODIGO_IDEA");
		int xcodigoUsuario = usuario_actual.getIdUsuario();
		
		GestionReunion reunion = new GestionReunion();
		
		try {
			reunion.insertarReunionesxAsesor(xasesoria, xcalifica, xcodigoUsuario, xcodigoIdea);
			request.setAttribute("lstReuniones",reunion.listarReunionesxAsesor(xcodigoUsuario));
			request.setAttribute("subtitulo", (String) session.getAttribute("SUB_TITULO"));
			request.setAttribute("codigoMsg", "OK");
			request.setAttribute("servletMsg", "Lista de Asesorias...");
			//request.setAttribute("subtitulo", xsubtitulo);
		} catch (DAOExcepcion e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			request.setAttribute("codigoMsg", "ERROR");
			request.setAttribute("servletMsg", "Asesoria no se pudo registrar");
		}
		
		// Volver a mostrar el JSP
		RequestDispatcher rd = request
				.getRequestDispatcher("detalleReuniones.jsp");
		rd.forward(request, response);

		
		
	}

}
